<?php

/*
 * 评价管理
 */

namespace app\seller\controller;

class Evaluate extends \app\common\controller\Seller
{

    /**
     * 评价列表
     */
    public function index()
    {
        $model_evaluate_goods = model('EvaluateGoods');

        $condition = array();
        if (!empty($_GET['goods_name'])) {
            $condition['geval_goodsname'] = array('like', '%' . $_GET['goods_name'] . '%');
        }
        if (!empty($_GET['member_name'])) {
            $condition['geval_frommembername'] = array('like', '%' . $_GET['member_name'] . '%');
        }
        $condition['geval_storeid'] = $this->store_id;
        $goodsevallist = $model_evaluate_goods->getEvaluateGoodsList($condition, 10, 'geval_id desc');

        $this->assign('goodsevallist', $goodsevallist);
        $this->assign('left_nav', 'evaluate');
        //to do page
        //$this->assign('show_page', $model_evaluate_goods->showpage());
        return $this->fetch('goods/evaluate');
    }

    /**
     * 解释来自买家的评价
     */
    public function explain_save()
    {
        $geval_id = input('post.geval_id/d');
        $geval_explain = input('post.geval_explain', '', 'trim');

        //验证表单
        if (!$geval_explain) {
            $data['result'] = false;
            $data['message'] = '解释内容不能为空';
            return json($data);
        }

        $data = array();
        $data['result'] = true;

        $model_evaluate_goods = model('Common/EvaluateGoods');

        $evaluate_info = $model_evaluate_goods->getEvaluateGoodsInfoByID($geval_id, $this->store_id);
        if (empty($evaluate_info)) {
            $data['result'] = false;
            $data['message'] = '参数错误';
            return json($data);
        }

        $update = array('geval_explain' => $geval_explain);
        $condition = array('geval_id' => $geval_id);
        $result = $model_evaluate_goods->editEvaluateGoods($update, $condition);

        if ($result) {
            $data['message'] = '解释成功';
        } else {
            $data['result'] = false;
            $data['message'] = '解释保存失败';
        }
        return json($data);
    }

}
